# -*- coding: utf-8 -*-            
# @Author : chenliang
# @Time : 2025/3/31 09:30

# encoding:utf-8
import requests
from Common.dingtalk import Ding
from Common.zentao import Zentao
from datetime import datetime
import webbrowser


ak_baidu = "knwViLhH7pi1pJS6wnYpuxlb2rKWZUmk"
ak_tengxun = "LXPBZ-AYIEH-NMXDP-WRQPW-MI3N7-YDFKF"


ak_dist={}

#百度服务端
url_baidu = "https://api.map.baidu.com/directionlite/v1/driving"
params = {
    "origin":    "40.01116,116.339303",
    "destination":    "39.936404,116.452562",
    "ak":       ak_baidu,

}

response_baidu = requests.get(url=url_baidu, params=params)
if response_baidu:
    result=response_baidu.json()
    #print(result['message'])
    if result['message'] !='ok':
        ak_dist['百度服务端'] = f'{ak_baidu}' + '|' + result['message']


#腾讯地图
url_tengxun = "https://apis.map.qq.com/ws/place/v1/suggestion"
params = {
    "keyword":    "武进",
    "region":   "全国",
    "key":  ak_tengxun,
    "region_fix": 0,
    "policy":1

}

response_tengxun = requests.get(url=url_tengxun, params=params)
if response_tengxun:
    result=response_tengxun.json()
    #print(result['message'])
    if result['message'] != 'query ok':
        ak_dist['腾讯地图'] = f'{ak_tengxun}' + '|' + result['message']


# ak = "QhtwXNfSgN7Wad6CuFp4zrUnXCGIZGAF1"  # 替换为待验证的AK
# url = f"http://api.map.baidu.com/reverse_geocoding/v3/?ak={ak}&output=json&coordtype=wgs84ll&location=39.904993,116.401735"  # 北京测试坐标
# response = requests.get(url)
# result = response.json()
#print(result)


# # 百度web
# file_path = "Ansible/js_api.html"
# webbrowser.open('http://localhost:63342/' + file_path)
#
# try:
#     webbrowser.open('http://localhost:63342/' + file_path)
# except Exception as e:
#     print(f"Error: {e}")





if len(ak_dist)!=0:
    result=Ding().ak_message(ak=ak_dist,phone='17625890895')
    print(result)
    Ding().send_to_dingtalk('https://oapi.dingtalk.com/robot/send?access_token=69084d85fde044caf8b3e12128779646cf1552d0606208923186cfabb275e211',result)